package demo1;

import java.util.Scanner;

//二叉树的遍历

class TreeNode {
    public char val;
    public TreeNode left;
    public TreeNode right;

    public TreeNode(char val) {
        this.val = val;
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while(input.hasNextLine()) {
            String str = input.nextLine();
            TreeNode root = createTree(str);
            inOrder(root);
        }
    }
    public static int i;
    public static TreeNode createTree(String str) {
        TreeNode root = null;
        if (i >= str.length()) {
            return root;
        }
        if (str.charAt(i) != '#') {
            root = new TreeNode(str.charAt(i));
            i++;
            root.left = createTree(str);
            root.right = createTree(str);

        } else {
            i++;
        }
        return root;
    }
    public static void inOrder(TreeNode root) {
        if (root == null) {
            return;
        }
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);
    }
}
